package com.itfreer.data.general.utils;

import com.itfreer.data.general.GlobalParameter;

/**
 * 定义获取SQL执行错误后的执行错误信息
 */
public class SqlMessageUtils {
	
	/*
	 * 获取执行错误信息
	 */
	public static String getMessage(Exception innerException, String sql,
			GlobalParameter[] para) {
		String result = "SQL执行错误：" + innerException.getMessage();
		result += "\n执行的SQL：" + sql;
		result += "\n参数：";
		if (para != null && para.length > 0) {
			Boolean isAddParameter = false;
			for (GlobalParameter item : para) {
				if (item == null) {
					continue;
				}
				if (item.getParaValue() == null) {
					result += item.getParaName() + ":Null,";
				} else {
					result += item.getParaName() + ":"
							+ item.getParaValue().toString() + ",";
				}
				isAddParameter = true;
			}
			if (isAddParameter) {
				result = result.substring(0, result.length() - 1);
			}
		}
		return result;
	}
}